<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib  prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<table border="1">
    <tr>
        <td rowspan="3">
            <table border="1">
                <tr>
                    <td>
                        <strong>Customer: </strong>
                    </td>
                    <td>
                        <c:choose>
                            <c:when test="${customerViewHisInvoice eq true}">
                                ${invoice.customer.name}
                            </c:when>
                            <c:when test="${invoice.customer!=null}">
                                <a href="<%=request.getContextPath()%>/customer/view?id=${invoice.customer.autoId}">${invoice.customer.name}</a>
                            </c:when>
                            <c:otherwise>
                                (None)
                            </c:otherwise>
                        </c:choose>
                    </td>
                </tr>
            </table>
        </td>
        <td>
            <strong>No.</strong>
        </td>
        <td>
            ${invoice.number}
        </td>
    </tr>
    <tr>
        <td>
            <strong>Date:</strong>
        </td>
        <td>
            <fmt:formatDate pattern="MMM d, yyyy" value="${invoice.createdDate}"/>
        </td>
    </tr>
    <tr>
        <td>
            <strong>Saler ID: </strong>
        </td>
        <td>
            --
        </td>
    </tr>
</table>
<table border="1">
    <tr>
        <td>
            <strong>No.</strong>
        </td>
        <td>
            <strong>Product Code</strong>
        </td>
        <td>
            <strong>Product Name</strong>
        </td>
        <td>
            <strong>Quantity</strong>
        </td>
        <td>
            <strong>Price</strong>
        </td>
        <td>
            <strong>Sub Total</strong>
        </td>
    </tr>
    <c:set var="total" value="0"/>
    <c:forEach var="invoiceItem" items="${invoice.invoiceItems}" varStatus="counter">
        <tr>
            <td>
                ${counter.count}
            </td>
            <td>
                ${invoiceItem.product.code}
            </td>
            <td>
                ${invoiceItem.product.name}
            </td>
            <td>
                ${invoiceItem.quantity}
                (${invoiceItem.product.unit})
            </td>
            <td>
                x ${invoiceItem.price} VND
            </td>
            <td>
                ${invoiceItem.price * invoiceItem.quantity} VND
                <c:set var="total" value="${total + invoiceItem.price * invoiceItem.quantity}"/>
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="4" align="right">
            Total
        </td>
        <td colspan="2">
            <strong>${total}</strong>
        </td>
    </tr>
    <tr>
        <td colspan="4" align="right">
            Discount
        </td>
        <td colspan="2">
            <strong>${invoice.discount} VND</strong>
        </td>
    </tr>
    <tr>
        <td colspan="4" align="right">
            Must pay
        </td>
        <td colspan="2">
            <strong>${total - invoice.discount} VND</strong>
        </td>
    </tr>
</table>
